***This command file allows for replication of results and tables from the 2021 Online Survey.


*** Survey Recodes
	*** NAAS 2016, NOT POSTED BY US but publicly available from ICPSR
	
		* Recoded Race

			gen QETHNICITY_QUOTA = 1 if RACE==3
			replace QETHNICITY_QUOTA = 2 if RACE==4
			replace QETHNICITY_QUOTA = 3 if RACE==1
			replace QETHNICITY_QUOTA = 4 if RACE==6

			label define QETHNICITY_QUOTA 1 "White" 2 "Black" 3 "Asian" 4 "Latino"
			label variable QETHNICITY_QUOTA QETHNICITY_QUOTA

		* Cleaned Importance Items

			gen QIMPORTANCERArev01 = (Q7_5A-1)/3 if Q7_5A<=4
			gen QIMPORTANCERBrev01 = (Q7_5B-1)/3 if Q7_5B<=4
			gen QIMPORTANCERCrev01 = (Q7_5C-1)/3 if Q7_5C<=4
			gen QIMPORTANCERDrev01 = (Q7_5D-1)/3 if Q7_5D<=4
			gen QIMPORTANCERErev01 = (Q7_5E-1)/3 if Q7_5E<=4
			gen QIMPORTANCERFrev01 = (Q7_5F-1)/3 if Q7_5F<=4

			*** The following code generates a "standard error" variable for each importance variable, for use with the "collapse" command later on when producing Figure 6
			
			foreach var of varlist QIMPORTANCERArev01 QIMPORTANCERBrev01 QIMPORTANCERCrev01 QIMPORTANCERDrev01 QIMPORTANCERErev01 		QIMPORTANCERFrev01 { gen se_`var'=`var'
		}



	*** Based on our survey, posted file = "2021 Online Survey"

		*** Social Background

		gen parborn = 0 if QMOTHERBORN == 0 & QFATHERBORN == 0
		replace parborn = 1 if QMOTHERBORN == 1 | QFATHERBORN == 1

		tab QGENDER, gen(gender)

		gen income = QINCOME if QINCOME>=1&QINCOME<=5
		replace income = 6 if QINCOME>=6&QINCOME<=11
		replace income = 7 if QINCOME==99

		label define income 1 "<$25,000" 2 "$25,000-$34,999" 3 "$35,000-$49,999" 4 "$50,000-$74,999" 5 "$75,000-$99,999" 6 ">$100,000" 7 "Prefer not to say" 

		label values income income

		tab income, gen(income)

		tab QEMPLOYMENT, gen(employment)
		tab QEDUCATION, gen(education)

		*** Importance of More [X] in Congress Variables

		foreach e of varlist QIMPORTANCERA QIMPORTANCERB QIMPORTANCERC QIMPORTANCERD QIMPORTANCERE QIMPORTANCERF QIMPORTANCERG {
			gen `e'rev01 = ((`e'-4)/3)*-1
			
		}

		label variable QIMPORTANCERArev01 "Importance of more [OWN RACE] in Congress"
		label variable QIMPORTANCERBrev01 "Importance of more Asian-Americans in Congress"
		label variable QIMPORTANCERCrev01 "Importance of more [OWN ASIAN ORIGIN] in Congress"
		label variable QIMPORTANCERDrev01 "Importance of more women in Congress"
		label variable QIMPORTANCERErev01 "Importance of more [R PID] in Congress"
		label variable QIMPORTANCERFrev01 "Importance of people in Congress representing issues R cares about"

		label define importrevrecode 0 "Not important" 1 "Extremely important"

		label values QIMPORTANCERArev01 importrevrecode
		label values QIMPORTANCERBrev01 importrevrecode
		label values QIMPORTANCERCrev01 importrevrecode
		label values QIMPORTANCERDrev01 importrevrecode
		label values QIMPORTANCERErev01 importrevrecode
		label values QIMPORTANCERFrev01 importrevrecode
		label values QIMPORTANCERGrev01 importrevrecode

		*** The following code generates a "standard error" variable for each importance variable, for use with the "collapse" command later on when producing Figure 6
		
		foreach var of varlist QIMPORTANCERArev01 QIMPORTANCERBrev01 QIMPORTANCERCrev01 QIMPORTANCERDrev01 QIMPORTANCERErev01 QIMPORTANCERFrev01 { 
    gen se_`var'=`var'
}

		*** Vignette DVs, Note: With and Without Imputing DKs to "Neither" category

		foreach e of varlist QVIGRESPRUNDERSTANDSISSUES QVIGRESPRIFWON QVIGRESPRMOREPEOPLE {
			gen `e'recode = `e' if `e'~=98
			label values `e'recode labels23
		}

		gen candfavorindex3 = (QVIGRESPRUNDERSTANDSISSUESrecode+QVIGRESPRIFWONrecode+QVIGRESPRMOREPEOPLErecode)/3
		label variable candfavorindex3 "Vignette Candidate Favorability Index (3-Item, 0-4)"
		label values candfavorindex3 labels23

		foreach e of varlist QVIGRESPRUNDERSTANDSISSUES QVIGRESPRIFWON QVIGRESPRMOREPEOPLE {
			gen `e'rec2 = `e' if `e'~=98
			replace `e'rec2 = 2 if `e'==98
			label values `e'rec2 labels23
		}

		gen candfavorindex3imp = (QVIGRESPRUNDERSTANDSISSUESrec2+QVIGRESPRIFWONrec2+QVIGRESPRMOREPEOPLErec2)/3
		label variable candfavorindex3imp "Vignette Candidate Favorability Index, DK Imputed Neutral (3-Item, 0-4)"
		label values candfavorindex3 labels23

*** Figure 6

	*** To arrive at this figure, one needs to derive two separate aggregated datasets, one from the NAAS 2016 (for left panel) and the other from our survey (right panel) These aggregated datasets are produced using the following, which will work on BOTH individual-level files if the above recodes have been carried out:

collapse (mean) QIMPORTANCERArev01 QIMPORTANCERBrev01 QIMPORTANCERCrev01 QIMPORTANCERDrev01 QIMPORTANCERErev01 QIMPORTANCERFrev01 (semean) se_QIMPORTANCERArev01 se_QIMPORTANCERBrev01 se_QIMPORTANCERCrev01 se_QIMPORTANCERDrev01 se_QIMPORTANCERErev01 se_QIMPORTANCERFrev01, by(QETHNICITY_QUOTA)

	*** Each dataset produced by the "collapse" command must be saved as a separate aggregated .dta, one tied to the NAAS 2016 and the other tied to our survey. The graphs underlying Figure 6 can be produced by running the following code on each independently:

		*** First, this code uses the _se from collapse to produce variables for upper and lower confidence bounds 
	
gen ucb = QIMPORTANCERArev01 + (1.96*se_QIMPORTANCERArev01)
gen lcb = QIMPORTANCERArev01 - (1.96*se_QIMPORTANCERArev01)

rename QIMPORTANCERArev01 Mean
label variable Mean "Mean Importance"
label variable ucb "Upper 95% Confidence Bound"
label variable lcb "Lower 95% Confidence Bound"
label define importance 0 "Not important" 1 "Extremely important"
label values Mean importance

		*** This leaves us with a dataset that has all the needed data for Figure 6, but is not yet usefully organized to produce that Figure. To do that, one needs to manually - I couldn't figure out an elegant operation to do this in Stata - reshape the data to fit the parameters in posted files "NAAS 2016 Aggregates for Figure 6" and "2021 Online Survey Aggregates for Figure 6". The only data that cannot be directly obtained are the values under "item", which are entirely arbitrary and used to fine-tune spacing of the plotted points on the x-axis.
		
		
		*** To actually make the graph, run (from the manually re-shaped Aggregated data file) the following code, which can be run on both the "NAAS 2016. Aggregates for Figure 6" and "2021 Online Survey Aggregates for Figure 6" files if all the variable names are consistent as they should be:
		
twoway (scatter Mean item if QETHNICITY_QUOTA==1, mcolor(black) msymbol(lgx)) (rcap lcb ucb item, lcolor(black)) (scatter Mean item if QETHNICITY_QUOTA==2, mcolor(black) msymbol(circle)) (scatter Mean item if QETHNICITY_QUOTA==3, mcolor(black) msymbol(triangle)) (scatter Mean item if QETHNICITY_QUOTA==4, mcolor(black) msymbol(square)), ytitle(Importance of More [X] in Congress) ytitle(, orientation(vertical)) ylabel(0(0.25)1, labsize(small) angle(horizontal)) xlabel(, labsize(vsmall) angle(horizontal) valuelabel) legend(order(1 "White" 3 "Black" 4 "Asian" 5 "Latino") rows(1))

		*** The two plots can then be combined using the stata command "graph combine"

*** Figure 7 (Vignette-Based)

	*** This figure was generated from the posted file "2021 Online Survey Aggregates for Figure 7". This file was manually generated on the basis of means and standard errors generated from the individual-level file "2021 Online Survey", using only Asian respondents. These means and standard errors were estimated for every possible combination of vignette randomizations based on respondent's Asian ethnic origin (QASIAN_ORIGIN) and vignette candidate ethnicity (CANDETH). I did it manually because I couldn't figure out a way to do this neatly in Stata and get the file shaped the way I needed it.

	*** From "2021 Online Survey Aggregates for Figure 7", the Figure 7 plot can be produced using:
	
	 twoway (bar Mean category, fcolor(gs8) lcolor(black)) (rcap LCB UCB category, lcolor(black)), xtitle("Candidate Ethnicity") xlabel(, labsize(small) angle(horizontal) valuelabel alternate) legend(off)


*** Figure 11 (Cross-over Voting, Vignette-Based)

	*** This figure was generated from the posted file "2021 Online Survey Aggregates for Figure 8". This file was manually generated on the basis of means and standard errors produced from the individual-level file "2021 Online Survey", using only non-Asian respondents. These means and standard errors were estimated for every possible combination of vignette randomizations based on respondent's ethnicity (QETHNICITY_QUOTA) and vignette candidate pan-ethnic identity (QCANDPANETHNIC). I did it manually because I couldn't figure out a way to do this neatly in Stata and get the file shaped the way I needed it.
		
	*** From "2021 Online Survey for Figure 11", the Figure 8 plot can be produced using:
	
		twoway (bar Mean category if category==1|category==5|category==9, fcolor(gs8) lcolor(black)) (rcap UCB LCB category if category==1|category==5|category==9, lcolor(black)) (bar Mean category if category==2|category==6|category==10, fcolor(gs0)) (rcap LCB UCB category if category==2|category==6|category==10, lcolor(black)) (bar Mean category if category==3|category==4|category==7|category==8|category==11|category==12, fcolor(gs14) lcolor(black)) (rcap LCB UCB category if category==3|category==4|category==7|category==8|category==11|category==12, lcolor(black)), ylabel(2(.2)3, angle(horizontal)) xtitle(Respondent Race & Candidate Race) xlabel(1(1)12, valuelabel alternate) legend(order(1 "In-Group Candidate" 3 "Asian Candidate" 5 "Other Outgroup Cand.") rows(1) size(small)) graphregion(fcolor(gs16))
		
*** Appendix Descriptives for "2021 Online Survey"

summarize QBORNUS parborn QUSCITIZEN gender1 gender2 gender3 income1 income2 income3 income4 income5 income6  income7 employment1 employment2 employment3 employment4 employment5 employment6 employment7 employment8 education1 education2 education3 education4 education5 education6 education7 education8 education9, cformat(9.3f)

